package com.huixi.utils;

import java.util.Map;

import com.huixi.Enums.JsonStatus;

import lombok.Data;

/**
 * ajax请求响应json结果
 */
@Data
public class JsonResult {

    private String msg;
    private Integer status = JsonStatus.ERROR.getCode();
    private Object data;
    private Map<String, Object> resultMap;

    public JsonResult() {

    }

    public JsonResult(Object data) {
    	this.status = 200;
    	this.msg = "OK";
    	this.data = data;
    }
    
    public JsonResult(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public JsonResult(Integer status, String msg, Object data) {
    	this.status = status;
    	this.msg = msg;
    	this.data = data;
    }
    
    public JsonResult(Integer status, String msg, Map<String, Object> resultMap) {
        this.status = status;
        this.msg = msg;
        this.resultMap = resultMap;
    }
    
    public static JsonResult build(Integer status, String msg) {
        return new JsonResult(status, msg, null);
    }
    
    public static JsonResult build(Integer status, String msg, Object data) {
        return new JsonResult(status, msg, data);
    }

    public static JsonResult ok(Object data) {
        return new JsonResult(data);
    }

    public static JsonResult ok() {
        return new JsonResult(null);
    }
    
}
